package com.shunan.miaosha.result;

public class  Result<T> {
	private int code;
	private String msg;
	private T data;
	
	private Result(int code, String msg, T data) {
		super();
		this.code = code;
		this.msg = msg;
		this.data = data;
	}
	private Result(int code, String msg) {
		super();
		this.code = code;
		this.msg = msg;
	}
	/**
	 * 成功时，调用这个方法来返回结果对象
	 * @param data
	 * @return
	 */
	public static <T> Result<T> success(T data){
		return new Result<T>(0,"success",data);
	}
	/**
	 * 失败时，调用这个方法返回结果对象
	 * @return
	 */
	public static Result<String> error(CodeMsg codemsg){
		return new Result<>(codemsg.getCode(),codemsg.getMsg());
	}
	
	public int getCode() {
		return code;
	}
	public String getMsg() {
		return msg;
	}
	public T getData() {
		return data;
	}
}
